package api.gif;

import android.content.Context;
import android.widget.Button;
import android.widget.ImageView;

import java.lang.ref.SoftReference;

/**
 * Created by My on 2017/11/22.
 */

public abstract class API_GIF {

    public static final String TYPE_ICON = "icon";
    public static final String TYPE_BUTTON = "button";//按钮
    public static final String OPEN_TYPE_BROWSER = "browser";//打开为浏览器
    public static final String OPEN_TYPE_WEBVIEW = "webview";//打开为webview
    public static final String FLASHLIGHT_ICON_CODE = "Light00";//手电筒广告位code
    public static final String CALCULATOR_LICAI_CODE = "calculate00";//计算器理财按钮的code
    public static final String CALCULATOR_ACCOUNT_CODE = "calculate01";//计算器记帐按钮的code
    public static final String COMPASS_ACCOUNT_CODE = "compass00";//指南针记帐按钮的code
    public static final String NOTE_GIFT_CODE = "note00";//便签code
    public static final String CLOCK_CODE = "clock_code";//闹钟的code
    public static final String TEST_CODE = "test";  //用来测试广告位
    public static final String EASYSOFT_CODE = "easysoft00";  //小白点code
    public static final String WEATHER_CODE = "weather00";  //天气code
    public static final String LOCKFOLDER = "lockfolder";  //一键锁屏code
    public static final String SPECIALLOCKFOLDER = "speciallockfolder";  //一键锁屏mate9code


    public abstract void giftExecute(Context context);
    public abstract void showBtn(String code ,Button button);
    public abstract void showGif(String code ,ImageView  imageView);
    public abstract void setOnGiftListener(OnGiftListener listener);
    public abstract Integer gteNowGifShowIndex();
    public abstract Integer gteNowBtnShowIndex();

    public interface OnGiftListener {
        void loadDataSuccess(); //没拉取数据成功
        void loadDataFailed(); //拉取数据失败
        void showGiftFailed(); //展示失败
        void showGiftSuccess(); //展示成功
    }



    public static String clazz = "com.idotools.two.box.GifManager_Api";
    private static SoftReference<API_GIF> sf;
    public synchronized static API_GIF getInstance() {
        if (sf == null || sf.get() == null) {
            Object o = null;
            try {
                o = Class.forName(clazz).newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            if (o != null) {
                sf = new SoftReference<>((API_GIF) o);
                return (API_GIF) o;
            }
        }
        return sf == null ? null : sf.get();
    }
}
